// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Conveyor Belt Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value1 : object.hitboxL
private alias object.value2 : object.hitboxR

// Player Aliases
private alias object.xpos : player.xpos
private alias object.gravity : player.gravity


// ========================
// Events
// ========================

event ObjectUpdate
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		if player[currentPlayer].gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object.entityPos, object.hitboxL, -20, object.hitboxR, 0, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
			if checkResult == true
				player[currentPlayer].xpos -= 0x20000
			end if
		end if
	next
end event


event ObjectStartup
	foreach (TypeName[Conveyor Belt], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].hitboxL = object[arrayPos0].propertyValue
		object[arrayPos0].hitboxL <<= 3
		object[arrayPos0].hitboxR = object[arrayPos0].hitboxL
		FlipSign(object[arrayPos0].hitboxL)
	next
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		editor.drawingOverlay = true
		
		// Draw the Conveyor Belt's hitbox
		
		// Right hitbox
		temp2 = object.propertyValue
		temp2 <<= 3
		
		// Left hitbox (just mirrored)
		temp0 = temp2
		FlipSign(temp0)
		
		temp1 = -20; temp3 = 0;
		CallFunction(EditorHelpers_DrawHitbox)
		
		editor.drawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 168, 18) // "trigger" - #0
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "size")
end event
